<template>
  <el-dialog
      :visible.sync="dialogVisible"
      title="发布申请"
      width="50%"
  >
    <div id="applyFormWrapper">
      <div style="text-align: center">
        <ApplyForm :formData="formData"/>
        <el-button size="mini" type="primary" @click="onSubmit">提交</el-button>
      </div>
    </div>
  </el-dialog>
</template>
<script>
import ApplyForm from "@/view/apply/applyForm/components/ApplyForm";
import {submitApplyApi} from "@/api/apply";


export default {
  data() {
    return {
      dialogVisible: false,
      formData: {appName: null, flowName: null, applyFormData: {}},
    };
  },
  components: {ApplyForm},
  methods: {
    async onSubmit() {
      console.log(this.formData);
      this.formData.applyTitle = "应用发布申请-" + this.formData.applyFormData.deployGroup.showName;
      await submitApplyApi(this.formData);
      this.$message({
        message: `提交申请成功`,
        type: "success",
      });
      this.$parent.loadDeployGroups();
      this.dialogVisible = false;
    },
    open(deployGroup) {
      this.formData = {
        appName: deployGroup.appName,
        flowName: "app_deploy",
        applyFormData: {
          deployGroup: {
            id: deployGroup.id,
            name: deployGroup.name,
            showName: deployGroup.showName,
            gitBranch: deployGroup.gitBranch
          }
        }
      };
      this.dialogVisible = true;
    }
  },
  async created() {
  }
};
</script>
<style scoped>


</style>
